// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements.  See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership.  The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License.  You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied.  See the License for the
// specific language governing permissions and limitations
// under the License.


suite("test_cast_to_largeint_from_datetimev2_1_part9") {

    // This test case is generated from the correspoinding be UT test case,
    // update this case if the correspoinding be UT test case is updated,
    // e.g.: ../run-be-ut.sh --run --filter=FunctionCastToDecimalTest.* --gen_regression_case
    sql "drop table if exists test_cast_to_largeint_from_datetimev2_1_part9_9_nullable;"
    sql "create table test_cast_to_largeint_from_datetimev2_1_part9_9_nullable(f1 int, f2 datetimev2(1)) properties('replication_num'='1');"
    sql """insert into test_cast_to_largeint_from_datetimev2_1_part9_9_nullable values (0, "9999-01-28 23:00:00.0"),(1, "9999-01-28 23:00:00.0"),(2, "9999-01-28 23:00:00.9"),(3, "9999-01-28 23:00:01.0"),(4, "9999-01-28 23:00:01.0"),(5, "9999-01-28 23:00:01.9"),(6, "9999-01-28 23:00:59.0"),(7, "9999-01-28 23:00:59.0"),(8, "9999-01-28 23:00:59.9"),(9, "9999-01-28 23:01:00.0"),(10, "9999-01-28 23:01:00.0"),(11, "9999-01-28 23:01:00.9"),(12, "9999-01-28 23:01:01.0"),(13, "9999-01-28 23:01:01.0"),(14, "9999-01-28 23:01:01.9"),(15, "9999-01-28 23:01:59.0"),(16, "9999-01-28 23:01:59.0"),(17, "9999-01-28 23:01:59.9"),(18, "9999-01-28 23:59:00.0"),(19, "9999-01-28 23:59:00.0"),
      (20, "9999-01-28 23:59:00.9"),(21, "9999-01-28 23:59:01.0"),(22, "9999-01-28 23:59:01.0"),(23, "9999-01-28 23:59:01.9"),(24, "9999-01-28 23:59:59.0"),(25, "9999-01-28 23:59:59.0"),(26, "9999-01-28 23:59:59.9"),(27, "9999-12-01 00:00:00.0"),(28, "9999-12-01 00:00:00.0"),(29, "9999-12-01 00:00:00.9"),(30, "9999-12-01 00:00:01.0"),(31, "9999-12-01 00:00:01.0"),(32, "9999-12-01 00:00:01.9"),(33, "9999-12-01 00:00:59.0"),(34, "9999-12-01 00:00:59.0"),(35, "9999-12-01 00:00:59.9"),(36, "9999-12-01 00:01:00.0"),(37, "9999-12-01 00:01:00.0"),(38, "9999-12-01 00:01:00.9"),(39, "9999-12-01 00:01:01.0"),
      (40, "9999-12-01 00:01:01.0"),(41, "9999-12-01 00:01:01.9"),(42, "9999-12-01 00:01:59.0"),(43, "9999-12-01 00:01:59.0"),(44, "9999-12-01 00:01:59.9"),(45, "9999-12-01 00:59:00.0"),(46, "9999-12-01 00:59:00.0"),(47, "9999-12-01 00:59:00.9"),(48, "9999-12-01 00:59:01.0"),(49, "9999-12-01 00:59:01.0"),(50, "9999-12-01 00:59:01.9"),(51, "9999-12-01 00:59:59.0"),(52, "9999-12-01 00:59:59.0"),(53, "9999-12-01 00:59:59.9"),(54, "9999-12-01 01:00:00.0"),(55, "9999-12-01 01:00:00.0"),(56, "9999-12-01 01:00:00.9"),(57, "9999-12-01 01:00:01.0"),(58, "9999-12-01 01:00:01.0"),(59, "9999-12-01 01:00:01.9"),
      (60, "9999-12-01 01:00:59.0"),(61, "9999-12-01 01:00:59.0"),(62, "9999-12-01 01:00:59.9"),(63, "9999-12-01 01:01:00.0"),(64, "9999-12-01 01:01:00.0"),(65, "9999-12-01 01:01:00.9"),(66, "9999-12-01 01:01:01.0"),(67, "9999-12-01 01:01:01.0"),(68, "9999-12-01 01:01:01.9"),(69, "9999-12-01 01:01:59.0"),(70, "9999-12-01 01:01:59.0"),(71, "9999-12-01 01:01:59.9"),(72, "9999-12-01 01:59:00.0"),(73, "9999-12-01 01:59:00.0"),(74, "9999-12-01 01:59:00.9"),(75, "9999-12-01 01:59:01.0"),(76, "9999-12-01 01:59:01.0"),(77, "9999-12-01 01:59:01.9"),(78, "9999-12-01 01:59:59.0"),(79, "9999-12-01 01:59:59.0"),
      (80, "9999-12-01 01:59:59.9"),(81, "9999-12-01 23:00:00.0"),(82, "9999-12-01 23:00:00.0"),(83, "9999-12-01 23:00:00.9"),(84, "9999-12-01 23:00:01.0"),(85, "9999-12-01 23:00:01.0"),(86, "9999-12-01 23:00:01.9"),(87, "9999-12-01 23:00:59.0"),(88, "9999-12-01 23:00:59.0"),(89, "9999-12-01 23:00:59.9"),(90, "9999-12-01 23:01:00.0"),(91, "9999-12-01 23:01:00.0"),(92, "9999-12-01 23:01:00.9"),(93, "9999-12-01 23:01:01.0"),(94, "9999-12-01 23:01:01.0"),(95, "9999-12-01 23:01:01.9"),(96, "9999-12-01 23:01:59.0"),(97, "9999-12-01 23:01:59.0"),(98, "9999-12-01 23:01:59.9"),(99, "9999-12-01 23:59:00.0"),
      (100, "9999-12-01 23:59:00.0"),(101, "9999-12-01 23:59:00.9"),(102, "9999-12-01 23:59:01.0"),(103, "9999-12-01 23:59:01.0"),(104, "9999-12-01 23:59:01.9"),(105, "9999-12-01 23:59:59.0"),(106, "9999-12-01 23:59:59.0"),(107, "9999-12-01 23:59:59.9"),(108, "9999-12-28 00:00:00.0"),(109, "9999-12-28 00:00:00.0"),(110, "9999-12-28 00:00:00.9"),(111, "9999-12-28 00:00:01.0"),(112, "9999-12-28 00:00:01.0"),(113, "9999-12-28 00:00:01.9"),(114, "9999-12-28 00:00:59.0"),(115, "9999-12-28 00:00:59.0"),(116, "9999-12-28 00:00:59.9"),(117, "9999-12-28 00:01:00.0"),(118, "9999-12-28 00:01:00.0"),(119, "9999-12-28 00:01:00.9"),
      (120, "9999-12-28 00:01:01.0"),(121, "9999-12-28 00:01:01.0"),(122, "9999-12-28 00:01:01.9"),(123, "9999-12-28 00:01:59.0"),(124, "9999-12-28 00:01:59.0"),(125, "9999-12-28 00:01:59.9"),(126, "9999-12-28 00:59:00.0"),(127, "9999-12-28 00:59:00.0"),(128, "9999-12-28 00:59:00.9"),(129, "9999-12-28 00:59:01.0"),(130, "9999-12-28 00:59:01.0"),(131, "9999-12-28 00:59:01.9"),(132, "9999-12-28 00:59:59.0"),(133, "9999-12-28 00:59:59.0"),(134, "9999-12-28 00:59:59.9"),(135, "9999-12-28 01:00:00.0"),(136, "9999-12-28 01:00:00.0"),(137, "9999-12-28 01:00:00.9"),(138, "9999-12-28 01:00:01.0"),(139, "9999-12-28 01:00:01.0"),
      (140, "9999-12-28 01:00:01.9"),(141, "9999-12-28 01:00:59.0"),(142, "9999-12-28 01:00:59.0"),(143, "9999-12-28 01:00:59.9"),(144, "9999-12-28 01:01:00.0"),(145, "9999-12-28 01:01:00.0"),(146, "9999-12-28 01:01:00.9"),(147, "9999-12-28 01:01:01.0"),(148, "9999-12-28 01:01:01.0"),(149, "9999-12-28 01:01:01.9"),(150, "9999-12-28 01:01:59.0"),(151, "9999-12-28 01:01:59.0"),(152, "9999-12-28 01:01:59.9"),(153, "9999-12-28 01:59:00.0"),(154, "9999-12-28 01:59:00.0"),(155, "9999-12-28 01:59:00.9"),(156, "9999-12-28 01:59:01.0"),(157, "9999-12-28 01:59:01.0"),(158, "9999-12-28 01:59:01.9"),(159, "9999-12-28 01:59:59.0"),
      (160, "9999-12-28 01:59:59.0"),(161, "9999-12-28 01:59:59.9"),(162, "9999-12-28 23:00:00.0"),(163, "9999-12-28 23:00:00.0"),(164, "9999-12-28 23:00:00.9"),(165, "9999-12-28 23:00:01.0"),(166, "9999-12-28 23:00:01.0"),(167, "9999-12-28 23:00:01.9"),(168, "9999-12-28 23:00:59.0"),(169, "9999-12-28 23:00:59.0"),(170, "9999-12-28 23:00:59.9"),(171, "9999-12-28 23:01:00.0"),(172, "9999-12-28 23:01:00.0"),(173, "9999-12-28 23:01:00.9"),(174, "9999-12-28 23:01:01.0"),(175, "9999-12-28 23:01:01.0"),(176, "9999-12-28 23:01:01.9"),(177, "9999-12-28 23:01:59.0"),(178, "9999-12-28 23:01:59.0"),(179, "9999-12-28 23:01:59.9"),
      (180, "9999-12-28 23:59:00.0"),(181, "9999-12-28 23:59:00.0"),(182, "9999-12-28 23:59:00.9"),(183, "9999-12-28 23:59:01.0"),(184, "9999-12-28 23:59:01.0"),(185, "9999-12-28 23:59:01.9"),(186, "9999-12-28 23:59:59.0"),(187, "9999-12-28 23:59:59.0"),(188, "9999-12-28 23:59:59.9")
      ,(189, null);
    """

    sql "set enable_strict_cast=true;"
    qt_sql_9_strict 'select f1, cast(f2 as largeint) from test_cast_to_largeint_from_datetimev2_1_part9_9_nullable order by 1;'

    sql "set enable_strict_cast=false;"
    qt_sql_9_non_strict 'select f1, cast(f2 as largeint) from test_cast_to_largeint_from_datetimev2_1_part9_9_nullable order by 1;'

    sql "drop table if exists test_cast_to_largeint_from_datetimev2_1_part9_9_not_nullable;"
    sql "create table test_cast_to_largeint_from_datetimev2_1_part9_9_not_nullable(f1 int, f2 datetimev2(1)) properties('replication_num'='1');"
    sql """insert into test_cast_to_largeint_from_datetimev2_1_part9_9_not_nullable values (0, "9999-01-28 23:00:00.0"),(1, "9999-01-28 23:00:00.0"),(2, "9999-01-28 23:00:00.9"),(3, "9999-01-28 23:00:01.0"),(4, "9999-01-28 23:00:01.0"),(5, "9999-01-28 23:00:01.9"),(6, "9999-01-28 23:00:59.0"),(7, "9999-01-28 23:00:59.0"),(8, "9999-01-28 23:00:59.9"),(9, "9999-01-28 23:01:00.0"),(10, "9999-01-28 23:01:00.0"),(11, "9999-01-28 23:01:00.9"),(12, "9999-01-28 23:01:01.0"),(13, "9999-01-28 23:01:01.0"),(14, "9999-01-28 23:01:01.9"),(15, "9999-01-28 23:01:59.0"),(16, "9999-01-28 23:01:59.0"),(17, "9999-01-28 23:01:59.9"),(18, "9999-01-28 23:59:00.0"),(19, "9999-01-28 23:59:00.0"),
      (20, "9999-01-28 23:59:00.9"),(21, "9999-01-28 23:59:01.0"),(22, "9999-01-28 23:59:01.0"),(23, "9999-01-28 23:59:01.9"),(24, "9999-01-28 23:59:59.0"),(25, "9999-01-28 23:59:59.0"),(26, "9999-01-28 23:59:59.9"),(27, "9999-12-01 00:00:00.0"),(28, "9999-12-01 00:00:00.0"),(29, "9999-12-01 00:00:00.9"),(30, "9999-12-01 00:00:01.0"),(31, "9999-12-01 00:00:01.0"),(32, "9999-12-01 00:00:01.9"),(33, "9999-12-01 00:00:59.0"),(34, "9999-12-01 00:00:59.0"),(35, "9999-12-01 00:00:59.9"),(36, "9999-12-01 00:01:00.0"),(37, "9999-12-01 00:01:00.0"),(38, "9999-12-01 00:01:00.9"),(39, "9999-12-01 00:01:01.0"),
      (40, "9999-12-01 00:01:01.0"),(41, "9999-12-01 00:01:01.9"),(42, "9999-12-01 00:01:59.0"),(43, "9999-12-01 00:01:59.0"),(44, "9999-12-01 00:01:59.9"),(45, "9999-12-01 00:59:00.0"),(46, "9999-12-01 00:59:00.0"),(47, "9999-12-01 00:59:00.9"),(48, "9999-12-01 00:59:01.0"),(49, "9999-12-01 00:59:01.0"),(50, "9999-12-01 00:59:01.9"),(51, "9999-12-01 00:59:59.0"),(52, "9999-12-01 00:59:59.0"),(53, "9999-12-01 00:59:59.9"),(54, "9999-12-01 01:00:00.0"),(55, "9999-12-01 01:00:00.0"),(56, "9999-12-01 01:00:00.9"),(57, "9999-12-01 01:00:01.0"),(58, "9999-12-01 01:00:01.0"),(59, "9999-12-01 01:00:01.9"),
      (60, "9999-12-01 01:00:59.0"),(61, "9999-12-01 01:00:59.0"),(62, "9999-12-01 01:00:59.9"),(63, "9999-12-01 01:01:00.0"),(64, "9999-12-01 01:01:00.0"),(65, "9999-12-01 01:01:00.9"),(66, "9999-12-01 01:01:01.0"),(67, "9999-12-01 01:01:01.0"),(68, "9999-12-01 01:01:01.9"),(69, "9999-12-01 01:01:59.0"),(70, "9999-12-01 01:01:59.0"),(71, "9999-12-01 01:01:59.9"),(72, "9999-12-01 01:59:00.0"),(73, "9999-12-01 01:59:00.0"),(74, "9999-12-01 01:59:00.9"),(75, "9999-12-01 01:59:01.0"),(76, "9999-12-01 01:59:01.0"),(77, "9999-12-01 01:59:01.9"),(78, "9999-12-01 01:59:59.0"),(79, "9999-12-01 01:59:59.0"),
      (80, "9999-12-01 01:59:59.9"),(81, "9999-12-01 23:00:00.0"),(82, "9999-12-01 23:00:00.0"),(83, "9999-12-01 23:00:00.9"),(84, "9999-12-01 23:00:01.0"),(85, "9999-12-01 23:00:01.0"),(86, "9999-12-01 23:00:01.9"),(87, "9999-12-01 23:00:59.0"),(88, "9999-12-01 23:00:59.0"),(89, "9999-12-01 23:00:59.9"),(90, "9999-12-01 23:01:00.0"),(91, "9999-12-01 23:01:00.0"),(92, "9999-12-01 23:01:00.9"),(93, "9999-12-01 23:01:01.0"),(94, "9999-12-01 23:01:01.0"),(95, "9999-12-01 23:01:01.9"),(96, "9999-12-01 23:01:59.0"),(97, "9999-12-01 23:01:59.0"),(98, "9999-12-01 23:01:59.9"),(99, "9999-12-01 23:59:00.0"),
      (100, "9999-12-01 23:59:00.0"),(101, "9999-12-01 23:59:00.9"),(102, "9999-12-01 23:59:01.0"),(103, "9999-12-01 23:59:01.0"),(104, "9999-12-01 23:59:01.9"),(105, "9999-12-01 23:59:59.0"),(106, "9999-12-01 23:59:59.0"),(107, "9999-12-01 23:59:59.9"),(108, "9999-12-28 00:00:00.0"),(109, "9999-12-28 00:00:00.0"),(110, "9999-12-28 00:00:00.9"),(111, "9999-12-28 00:00:01.0"),(112, "9999-12-28 00:00:01.0"),(113, "9999-12-28 00:00:01.9"),(114, "9999-12-28 00:00:59.0"),(115, "9999-12-28 00:00:59.0"),(116, "9999-12-28 00:00:59.9"),(117, "9999-12-28 00:01:00.0"),(118, "9999-12-28 00:01:00.0"),(119, "9999-12-28 00:01:00.9"),
      (120, "9999-12-28 00:01:01.0"),(121, "9999-12-28 00:01:01.0"),(122, "9999-12-28 00:01:01.9"),(123, "9999-12-28 00:01:59.0"),(124, "9999-12-28 00:01:59.0"),(125, "9999-12-28 00:01:59.9"),(126, "9999-12-28 00:59:00.0"),(127, "9999-12-28 00:59:00.0"),(128, "9999-12-28 00:59:00.9"),(129, "9999-12-28 00:59:01.0"),(130, "9999-12-28 00:59:01.0"),(131, "9999-12-28 00:59:01.9"),(132, "9999-12-28 00:59:59.0"),(133, "9999-12-28 00:59:59.0"),(134, "9999-12-28 00:59:59.9"),(135, "9999-12-28 01:00:00.0"),(136, "9999-12-28 01:00:00.0"),(137, "9999-12-28 01:00:00.9"),(138, "9999-12-28 01:00:01.0"),(139, "9999-12-28 01:00:01.0"),
      (140, "9999-12-28 01:00:01.9"),(141, "9999-12-28 01:00:59.0"),(142, "9999-12-28 01:00:59.0"),(143, "9999-12-28 01:00:59.9"),(144, "9999-12-28 01:01:00.0"),(145, "9999-12-28 01:01:00.0"),(146, "9999-12-28 01:01:00.9"),(147, "9999-12-28 01:01:01.0"),(148, "9999-12-28 01:01:01.0"),(149, "9999-12-28 01:01:01.9"),(150, "9999-12-28 01:01:59.0"),(151, "9999-12-28 01:01:59.0"),(152, "9999-12-28 01:01:59.9"),(153, "9999-12-28 01:59:00.0"),(154, "9999-12-28 01:59:00.0"),(155, "9999-12-28 01:59:00.9"),(156, "9999-12-28 01:59:01.0"),(157, "9999-12-28 01:59:01.0"),(158, "9999-12-28 01:59:01.9"),(159, "9999-12-28 01:59:59.0"),
      (160, "9999-12-28 01:59:59.0"),(161, "9999-12-28 01:59:59.9"),(162, "9999-12-28 23:00:00.0"),(163, "9999-12-28 23:00:00.0"),(164, "9999-12-28 23:00:00.9"),(165, "9999-12-28 23:00:01.0"),(166, "9999-12-28 23:00:01.0"),(167, "9999-12-28 23:00:01.9"),(168, "9999-12-28 23:00:59.0"),(169, "9999-12-28 23:00:59.0"),(170, "9999-12-28 23:00:59.9"),(171, "9999-12-28 23:01:00.0"),(172, "9999-12-28 23:01:00.0"),(173, "9999-12-28 23:01:00.9"),(174, "9999-12-28 23:01:01.0"),(175, "9999-12-28 23:01:01.0"),(176, "9999-12-28 23:01:01.9"),(177, "9999-12-28 23:01:59.0"),(178, "9999-12-28 23:01:59.0"),(179, "9999-12-28 23:01:59.9"),
      (180, "9999-12-28 23:59:00.0"),(181, "9999-12-28 23:59:00.0"),(182, "9999-12-28 23:59:00.9"),(183, "9999-12-28 23:59:01.0"),(184, "9999-12-28 23:59:01.0"),(185, "9999-12-28 23:59:01.9"),(186, "9999-12-28 23:59:59.0"),(187, "9999-12-28 23:59:59.0"),(188, "9999-12-28 23:59:59.9");
    """

    sql "set enable_strict_cast=true;"
    qt_sql_9_strict 'select f1, cast(f2 as largeint) from test_cast_to_largeint_from_datetimev2_1_part9_9_not_nullable order by 1;'

    sql "set enable_strict_cast=false;"
    qt_sql_9_non_strict 'select f1, cast(f2 as largeint) from test_cast_to_largeint_from_datetimev2_1_part9_9_not_nullable order by 1;'

}